/*
 * @Author: zqx me_zqx@163.com
 * @Date: 2024-11-29 14:32:00
 * @LastEditors: zqx me_zqx@163.com
 * @LastEditTime: 2025-09-11 09:54:45
 * @FilePath: /XMate-h5/vite.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { fileURLToPath, URL } from "node:url";
import path from "path";
import vueSetupExtend from "vite-plugin-vue-setup-extend";
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
// import Components from "unplugin-vue-components/vite";
import { VantResolver } from "@vant/auto-import-resolver";
// import mockDevServerPlugin from "vite-plugin-mock-dev-server";
import viteCompression from "vite-plugin-compression";
import { createHtmlPlugin } from "vite-plugin-html";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";


const root = process.cwd();

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, root, "");
  return {
    base: env.VITE_BASE_URL || "/",
    plugins: [
      vue(),
      vueSetupExtend(),
      // mockDevServerPlugin(),
      // 生产环境 gzip 压缩资源
      viteCompression(),
      // 注入模板数据
      createHtmlPlugin({
        inject: {
          data: {
            ENABLE_ERUDA: env.VITE_ENABLE_ERUDA || "false"
          }
        }
      }),
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver(), VantResolver()]
      }),

    ],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url))
      }
    },
    server: {
      host: true,
      port: 5173,
      // https: {
      //   key: path.resolve(__dirname, './cert/172.17.21.122-key.pem'),
      //   cert: path.resolve(__dirname, './cert/172.17.21.122.pem')
      // },
      open: true,
      proxy: {
        "^/dev-api": {
          target: ""
        },
        "^/rest": {
          target: ""
        }
      }
    },
    build: {
      target: ['es2015', 'chrome63'],
      rollupOptions: {
        output: {
          chunkFileNames: "static/js/[name]-[hash].js",
          entryFileNames: "static/js/[name]-[hash].js",
          assetFileNames: "static/[ext]/[name]-[hash].[ext]"
        }
      },
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true
        }
      }
    }
  };
});
